package com.jec.module.sysconfig.service.convertor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jec.module.sysconfig.dao.BroadcastRepository;
import com.jec.module.sysconfig.entity.BroadcastConfig;
import com.jec.module.sysmonitor.dao.NetUnitRepository;
import com.jec.utils.Response;

/**
 * Created by jeremyliu on 05/10/2016.
 */
@Service
public class BroadcastConvertor implements Convertor<BroadcastConfig> {

    @Autowired
    private NetUnitRepository netUnitRepository;

    @Autowired
    private BroadcastRepository broadcastRepository;

    @Override
    public Response process(BroadcastConfig broadcastConfig) {
        Response response = Response.Builder().status(Response.STATUS_PARAM_ERROR);

        if(netUnitRepository.findOne(broadcastConfig.getNetunit()) == null)
            return response.message("网元不存在");
        if(broadcastRepository.existsByBroadcaster(broadcastConfig.getBroadcaster()))
            return response.message("广播机号码重复");
        if(broadcastRepository.existsByNetunitAndCode(broadcastConfig.getNetunit(), broadcastConfig.getCode()))
            return response.message("该网元业务为"+broadcastConfig.getCode()+"已配置");

        return response.status(Response.STATUS_SUCCESS);
    }

    @Override
    public Response checkBeforeRemove(int id) {
        return null;
    }
}
